<html>
<head>
	<title>CS633 Group Project :: Team 1 :: Address Book</title>
	<link rel="stylesheet" href="css/style.css" type="text/css">
	<script src="js/prototype.js" type="text/javascript"></script>
	<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
	<script src="js/jquery.maskedinput-1.2.2.min.js" type="text/javascript"></script>
	<script src="js/functions.js" type="text/javascript"></script>
	
	<script type="text/javascript">
		jQuery(function($)
		{
		   	$("#phone").mask("(999) 999-9999", {placeholder:" "});
		   	$("#state").mask("aa", {placeholder:" "});
		   	$("#zip").mask("99999", {placeholder:" "});
		});
		
		function validate()
		{
			var frm = window.document.forms[0];
			
			/* Last name */
			if(frm.lname.value.trim().length == 0)
			{
				alert('Please provide the last name.');
				frm.lname.focus();
				return false;
			}
			else
			{
				if(!isName(frm.lname.value.trim()))
				{
					alert('The last name should contain only alphabetical and space characters.');
					frm.lname.focus();
					frm.lname.select();
					return false;
				}
			}
			
			/* First name */
			if(frm.fname.value.trim().length == 0)
			{
				alert('Please provide the first name.');
				frm.fname.focus();
				return false;
			}
			else
			{
				if(!isName(frm.fname.value.trim()))
				{
					alert('The first name should contain only alphabetical and space characters.');
					frm.fname.focus();
					frm.fname.select();
					return false;
				}
			}
			
			/* Street address */
			if(frm.address.value.trim().length == 0)
			{
				alert('Please provide the address.');
				frm.address.focus();
				return false;
			}
			else
			{
				if(!isStreetAddress(frm.address.value.trim()))
				{
					alert('The street address should contain only alphanumeric, hyphen, underscore, period, #, and space characters.');
					frm.address.focus();
					frm.address.select();
					return false;
				}
			}

			/* City */			
			if(frm.city.value.trim().length == 0)
			{
				alert('Please provide the city.');
				frm.city.focus();
				return false;
			}
			else
			{
				if(!isStreetAddress(frm.city.value.trim()))
				{
					alert('The city should contain only alphanumeric, hyphen, underscore, period, #, and space characters.');
					frm.city.focus();
					frm.city.select();
					return false;
				}
			}

			/* State */
			if(frm.state.value.trim().length != 2)
			{
				alert('Please provide the state.');
				frm.state.focus();
				return false;
			}
			else
			{
				if(!isStateCode(frm.state.value.trim()))
				{
					alert('The state should contain a valid US State code. Example: NY');
					frm.state.focus();
					frm.state.select();
					return false;
				}
			}
			
			/* Zip Code */
			if(frm.zip.value.trim().length != 5)
			{
				alert('Please provide the zip code.');
				frm.zip.focus();
				return false;
			}
			
			/* Phone number */
			if(frm.phone.value.trim().length < 14)
			{
				alert('Please provide a valid phone number.');
				frm.phone.focus();
				frm.phone.select();
				return false;
			}
			
			/* E-mail */
			if(!isEmail(frm.email.value.trim()))
			{
				alert('Please provide a valid e-mail address.');
				frm.email.focus();
				return false;
			}
			else
			{
				if(!isEmailAddress(frm.email.value.trim()))
				{
					alert('The e-mail should contain only alphanumeric, hyphen, underscore, period, #, @, and space characters.');
					frm.email.focus();
					frm.email.select();
					return false;
				}
			}
			
			return true;
		}	

		function confirmDelete()
		{
			msg = "Are you sure you want to remove this entry?";
			return confirm(msg);
		}
	</script>
</head>
<body>
	<%
		entryID = Request("ID")
	
		'CONNECT TO DATABASE
		
			dbPath = "db/contacts.mdb"
		
			Set conn = Server.CreateObject("ADODB.Connection")
			MdbFilePath = Server.MapPath(dbPath)
			conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
		
		'GET FORM VALUES
			SQL_stmt = "SELECT * FROM People WHERE (PersonNo=" & entryID & ")"
			set RS = conn.execute(SQL_stmt)

		'GET FIELDS
			lname = RS("LastName")
			fname = RS("FirstName")
			address = RS("StreetAddress")
			city = RS("City")
			state = RS("State")
			zip = RS("ZipCode")
			phone = RS("PhoneNo")
			email = RS("EmailAddress")
			
		'SET STATE
			selAL = "" 
			selAK = ""
			selAZ = ""
			selCA = ""
			selCO = ""
			selCT = ""
			selDE = ""
			selDC = ""
			selFL = ""
			selGA = ""
			selHI = ""
			selID = ""
			selIL = ""
			selIN = ""
			selIA = ""
			selKS = ""
			selKY = ""
			selLA = ""
			selME = ""
			selMD = ""
			selMA = ""
			selMI = ""
			selMN = ""
			selMS = ""
			selMO = ""
			selMT = ""
			selNE = ""
			selNV = ""
			selNH = ""
			selNJ = ""
			selNM = ""
			selNY = ""
			selNC = ""
			selND = ""
			selOH = ""
			selOK = ""
			selOR = ""
			selPA = ""
			selRI = ""
			selSC = ""
			selSD = ""
			selTN = ""
			selTX = ""
			selUT = ""
			selVT = ""
			selVA = ""
			selWA = ""
			selWV = ""
			selWI = ""
			selWY = ""
			Select Case state
				Case "AL"
					selAL = "selected" 
				Case "AK"
					selAK = "selected"
				Case "AZ"
					selAZ = "selected"
				Case "CA"
					selCA = "selected"
				Case "CO"
					selCO = "selected"
				Case "CT"
					selCT = "selected"
				Case "DE"
					selDE = "selected"
				Case "DC"
					selDC = "selected"
				Case "FL"
					selFL = "selected"
				Case "GA"
					selGA = "selected"
				Case "HI"
					selHI = "selected"
				Case "ID"
					selID = "selected"
				Case "IL"
					selIL = "selected"
				Case "IN"
					selIN = "selected"
				Case "IA"
					selIA = "selected"
				Case "KS"
					selKS = "selected"
				Case "KY"
					selKY = "selected"
				Case "LA"
					selLA = "selected"
				Case "ME"
					selME = "selected"
				Case "MD"
					selMD = "selected"
				Case "MA"
					selMA = "selected"
				Case "MI"
					selMI = "selected"
				Case "MN"
					selMN = "selected"
				Case "MS"
					selMS = "selected"
				Case "MO"
					selMO = "selected"
				Case "MT"
					selMT = "selected"
				Case "NE"
					selNE = "selected"
				Case "NV"
					selNV = "selected"
				Case "NH"
					selNH = "selected"
				Case "NJ"
					selNJ = "selected"
				Case "NM"
					selNM = "selected"
				Case "NY"
					selNY = "selected"
				Case "NC"
					selNC = "selected"
				Case "ND"
					selND = "selected"
				Case "OH"
					selOH = "selected"
				Case "OK"
					selOK = "selected"
				Case "OR"
					selOR = "selected"
				Case "PA"
					selPA = "selected"
				Case "RI"
					selRI = "selected"
				Case "SC"
					selSC = "selected"
				Case "SD"
					selSD = "selected"
				Case "TN"
					selTN = "selected"
				Case "TX"
					selTX = "selected"
				Case "UT"
					selUT = "selected"
				Case "VT"
					selVT = "selected"
				Case "VA"
					selVA = "selected"
				Case "WA"
					selWA = "selected"
				Case "WV"
					selWV = "selected"
				Case "WI"
					selWI = "selected"
				Case "WY"
					selWY = "selected"
			End Select

		'CLOSE DATABASE CONNECTION
			conn.close
			set conn = nothing
			set sqlstmt = nothing
	%>
	<table width="100%">
		<!-- HEADER -->
		<tr style="padding:0px">
			<td><!--#include file ="header.asp"--></td>
		</tr>
		
		<!-- BODY -->
		<tr>
			<td align="center">
				<form name="NewEntry" method="post" action="action_edit.asp">
				<table bgcolor=#990000 width=1000 cellpadding=5 cellspacing=1 border=0>
					<tr class="header">
						<td colspan=2>Add New Entry
					<tr class="oddrow">
						<td width=200>Last Name
						<td><input id="lname" type="text" name="lname" size=25 maxlength="25" value="<%=lname%>">
					<tr class="evenrow">
						<td width=200>First Name
						<td><input id="fname" type="text" name="fname" size=25 maxlength="25" value="<%=fname%>">
					<tr class="oddrow"> 
						<td width=200>Address
						<td><input id="address" type="text" name="address" size=25 maxlength="50" value="<%=address%>">
					<tr class="evenrow">
						<td width=200>City
						<td><input id="city" type="text" name="city" size=25 maxlength="26" value="<%=city%>">
					<tr class="oddrow">
						<td width=200>State
						<td>
						
						<!--
						<input id="state" type="text" name="state" size=2 maxlength="2" value="<%=state%>" onblur="this.value = this.value.toUpperCase();">
						// -->
						
						<select name="state">
							<option value="AL" <%=selAL%>>AL</option>
							<option value="AK" <%=selAK%>>AK</option>
							<option value="AZ" <%=selAZ%>>AZ</option>
							<option value="AR" <%=selAR%>>AR</option>
							<option value="CA" <%=selCA%>>CA</option>
							<option value="CO" <%=selCO%>>CO</option>
							<option value="CT" <%=selCT%>>CT</option>
							<option value="DE" <%=selDE%>>DE</option>
							<option value="DC" <%=selDC%>>DC</option>
							<option value="FL" <%=selFL%>>FL</option>
							<option value="GA" <%=selGA%>>GA</option>
							<option value="HI" <%=selHI%>>HI</option>
							<option value="ID" <%=selID%>>ID</option>
							<option value="IL" <%=selIL%>>IL</option>
							<option value="IN" <%=selIN%>>IN</option>
							<option value="IA" <%=selIA%>>IA</option>
							<option value="KS" <%=selKS%>>KS</option>
							<option value="KY" <%=selKY%>>KY</option>
							<option value="LA" <%=selLA%>>LA</option>
							<option value="ME" <%=selME%>>ME</option>
							<option value="MD" <%=selMD%>>MD</option>
							<option value="MA" <%=selMA%>>MA</option>
							<option value="MI" <%=selMI%>>MI</option>
							<option value="MN" <%=selMN%>>MN</option>
							<option value="MS" <%=selMS%>>MS</option>
							<option value="MO" <%=selMO%>>MO</option>
							<option value="MT" <%=selMT%>>MT</option>
							<option value="NE" <%=selNE%>>NE</option>
							<option value="NV" <%=selNV%>>NV</option>
							<option value="NH" <%=selNH%>>NH</option>
							<option value="NJ" <%=selNJ%>>NJ</option>
							<option value="NM" <%=selNM%>>NM</option>
							<option value="NY" <%=selNY%>>NY</option>
							<option value="NC" <%=selNC%>>NC</option>
							<option value="ND" <%=selND%>>ND</option>
							<option value="OH" <%=selOH%>>OH</option>
							<option value="OK" <%=selOK%>>OK</option>
							<option value="OR" <%=selOR%>>OR</option>
							<option value="PA" <%=selPA%>>PA</option>
							<option value="RI" <%=selRI%>>RI</option>
							<option value="SC" <%=selSC%>>SC</option>
							<option value="SD" <%=selSD%>>SD</option>
							<option value="TN" <%=selTN%>>TN</option>
							<option value="TX" <%=selTX%>>TX</option>
							<option value="UT" <%=selUT%>>UT</option>
							<option value="VT" <%=selVT%>>VT</option>
							<option value="VA" <%=selVA%>>VA</option>
							<option value="WA" <%=selWA%>>WA</option>
							<option value="WV" <%=selWV%>>WV</option>
							<option value="WI" <%=selWI%>>WI</option>
							<option value="WY" <%=selWY%>>WY</option>
						</select>
					<tr class="evenrow">
						<td width=200>Zip
						<td><input id="zip" type="text" name="zip" size=12 maxlength="5" value="<%=zip%>">
					<tr class="oddrow">
						<td width=200>Phone
						<td><input id="phone" type="text" name="phone" size=20 value="<%=phone%>">
					<tr class="evenrow">
						<td width=200>E-mail
						<td><input id="email" type="text" name="email" size=25 maxlength="50" value="<%=email%>">
						<input id="entryID" type="hidden" name="entryID" size=25 value="<%=entryID%>">
					<tr class="oddrow">
						<td width=200>
						<td><input type="button" onclick="history.go(-1);" value="&lt&lt Back" />&nbsp;&nbsp;
						<input type="submit" onclick="return validate();" value="Change Entry">&nbsp;&nbsp;
						<input type="button" onclick="if(confirmDelete()) { location.href='action_delete.asp?ID=<%=entryID%>'; }" value="Delete Entry">&nbsp;&nbsp;		<input type="reset" value="Reset">
				</table>
				</form>
			</td>
		</tr>
		
		<!-- FOOTER -->
		<tr style="padding:0px">
			<td><!--#include file ="footer.asp"--></td>
		</tr>			
	</table>
</body>